/*
package com.imay.live.activity;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.imay.base.adapter.SimpleFragmentPagerAdapter;
import com.imay.base.fragment.BaseFragment;
import com.imay.base.widget.TitleBar;
import com.imay.cocos.IMayCocos;
import com.imay.cocos.IMayCocosNetManager;
import com.imay.live.Constants;
import com.imay.live.IMApplication;
import com.imay.live.R;
import com.imay.live.activity.dynamics.ReleaseActivity;
import com.imay.live.activity.recharge.RechargeActivity;
import com.imay.live.analytics.MobclickAgent;
import com.imay.live.cache.AdsPersenter;
import com.imay.live.cache.UserInfoCache;
import com.imay.live.fragment.MainActionButtonFragment;
import com.imay.live.fragment.NoticeFragment;
import com.imay.live.fragment.ProfileFragment;
import com.imay.live.fragment.discovery.DiscoveryFragment;
import com.imay.live.fragment.discovery.LoadFragment;
import com.imay.live.fragment.dynamics.DynamicsFragment;
import com.imay.live.heartlikeslib.byeburgernavigationview.ByeBurgerBehavior;
import com.imay.live.helper.DialogFragmentHelper;
import com.imay.live.helper.EventHelper;
import com.imay.live.helper.H5Helper;
import com.imay.live.helper.LocationHelper;
import com.imay.live.helper.RoomHouseHelper;
import com.imay.live.helper.ThreadManager;
import com.imay.live.helper.TitleBarClickHelper;
import com.imay.live.manager.AccountManager;
import com.imay.live.manager.DynamicsNotifyManager;
import com.imay.live.manager.MessageManager;
import com.imay.live.manager.NoticeBubbleManager;
import com.imay.live.manager.UnreadManager;
import com.imay.live.model.AdsModel;
import com.imay.live.model.SysConfigModel;
import com.imay.live.model.UnreadModel;
import com.imay.live.model.UserInfoModel;
import com.imay.live.model.UserModel;
import com.imay.live.params.IMParams;
import com.imay.live.proto.Result;
import com.imay.live.proto.helper.ProtoCallBack;
import com.imay.live.proto.helper.ProtoHttpFactory;
import com.imay.live.proto.helper.ProtoRequestHelper;
import com.imay.live.update.CheckUpdateApp;
import com.imay.live.utils.AnimationUtil;
import com.imay.live.utils.AppUtil;
import com.imay.live.utils.ViewUtil;
import com.imay.live.view.custom.NavigationTabView;
import com.imay.tbas_api.IMYTBASObject;

import static com.imay.live.manager.MessageManager.NewWarnType.IMBubbleCommentType;
import static com.imay.live.manager.MessageManager.NewWarnType.IMBubbleFollowType;
import static com.imay.live.manager.MessageManager.NewWarnType.IMBubbleGiftType;
import static com.imay.live.manager.MessageManager.NewWarnType.IMBubbleMindType;
import static com.imay.live.manager.MessageManager.NewWarnType.IMBubblePraiseType;
import static com.imay.live.manager.MessageManager.NewWarnType.IMBubbleRePostType;
import static com.imay.live.manager.UnreadManager.TYPE_UNREAD_MESSAGE;
import static com.imay.live.manager.UnreadManager.TYPE_UNREAD_SYSTEM_PROFILE;
import static com.imay.live.proto.ResultCode.CodeSuccess;

*/
/**
 * Created by jeaman on 2017/2/15.
 *//*


public class MainActivity extends BaseCocosActivity implements AppBarLayout.OnOffsetChangedListener, View.OnClickListener, LocationHelper.OnLocationListener, ProtoCallBack, UnreadManager.ChangeUnreadStatusListener, DynamicsNotifyManager.DynamicNotifyListener, IMayCocosNetManager.OnCocosShopListener, AdsPersenter.OnShowListener {
    private final static String BUNDLE_NAME_SELECT_TAB_ID = "SELECT_TAB_ID";
    //TAB资源id
    private final static int TAB_TITLES[] = new int[]{R.string.str_bottom_dongtai, R.string.str_bottom_faxian, R.string.str_bottom_tongzhi, R.string.str_bottom_me};

    TitleBar titleBar;
    private ViewPager mViewPager;
    private AppBarLayout mAppBarLayout;

    private DiscoveryFragment mDiscoveryFragment;
    private Handler dynamicsFragmentHandler;

    private SimpleFragmentPagerAdapter mViewPagerAdapter;
    private int mSelectTabId;
    private long mPressBackTime = 0;
    private SparseArray<NavigationTabView> mTabButtonArray = new SparseArray<>();

    //标题栏滑动相关
    private float mTitleBarHeight;
    float mLastXScale = 1;
    float mLastScale = 1;
    float mLastAlpha = 1;
    private int mLastVerticalOffset;
    private boolean mExpanded;
    LinearLayout main_rg_tab;
    int tabH;
    private Animator mTabAnimator;
    private View profileSysNoticeView;
    private FrameLayout fl_cocos_view_container;
    private RelativeLayout container;
    private ImageView iv_profile_system_notice_red;
    private AdsPersenter adsPersenter;
    private CheckUpdateApp checkUpdateApp;
    private RoomHouseHelper roomHouseHelper;//建楼卡
    private IMYTBASObject mSocketNotify;
    private boolean ispause = true;
    */
/**
     * ==========权限==========
     *//*

    private final static int PERMISSION_REQUEST_CODE_LOCATION = 1;
    private final static int PERMISSION_REQUEST_CODE_EXTERNAL_STORAGE = 2;

    private boolean mShowLocation = true;   //是否开启定位
    private boolean mWaitCheckLocalPermission;
    private boolean mShowExternalStorage = true;
    private boolean mWaitCheckSDPermission;
    private String loadSystemNoticeRedCommand;
    private String loadSysParamGameShowRequest;
    private NavigationTabView radiodynamics, radiodiscovery, radionotice, radiomine;
    private boolean isDynamicsRed = false;
    private boolean hasUnreadNotice;
    private boolean hasUnreadMessage;

    private NoticeFragment noticeFragment;
    private FrameLayout fl_main;
    private boolean cocosViewShowing;
    private int show;
    private boolean hasLoadComplete;
    private boolean willshow = true;//是否允许展示其他弹窗
    private View iv_bgwen;
    private boolean appLayoutHide = false;

    */
/**
     * @param activity
     * @param queryStr H5回调要跳转的页面字符串数据
     *//*

    public static void startActivity(Activity activity, String queryStr) {
        Intent intent = new Intent(activity, MainActivity.class);
        intent.putExtra(H5Helper.H5REDIRECTION_KEY, queryStr);
        activity.startActivity(intent);
    }

    */
/**
     * @param activity
     *//*

    public static void startActivityForUmengPush(Context activity, String queryStr) {
        Intent intent = new Intent(activity, MainActivity.class);
        intent.putExtra(H5Helper.H5REDIRECTION_KEY, queryStr);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(BUNDLE_NAME_SELECT_TAB_ID, mSelectTabId);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String url = intent.getStringExtra(H5Helper.H5REDIRECTION_KEY);
        if (!TextUtils.isEmpty(url) && (url.indexOf("type=10", 0) > -1 || url.indexOf("type=13", 0) > -1)) {
            try {
                Uri uri = Uri.parse(url);
                String equiqId = uri.getQueryParameter("equiqId");
                int id = Integer.valueOf(equiqId);
                showMarketPannel(id);
                willshow = false;
                return;
            } catch (Exception e) {
            }
            showMarketPannel(null);
        } else if (!TextUtils.isEmpty(url) && (url.indexOf("type=1", 0) > -1)) {
            // 打开回调页面
            H5Helper.startActivity(url, this);
        }


    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initPermission();

        // 打开回调页面
        boolean hasout = H5Helper.startActivity(getIntent().getStringExtra(H5Helper.H5REDIRECTION_KEY), this);

        ((IMApplication) getApplication()).userLoseNotify();

        //CoordinatorLayout coordinatorLayout = $(R.id.main_cdl);
        main_rg_tab = $(R.id.main_rg_tab);


        mTitleBarHeight = getResources().getDimension(R.dimen.title_bar_height);
        titleBar = $(R.id.main_tb_title_bar);
        iv_bgwen = $(R.id.iv_bgwen);
        setTitleBar(titleBar);
        //coordinatorLayout.onStopNestedScroll(titleBar);

        mAppBarLayout = $(R.id.main_abl_appbar);
        fl_cocos_view_container = $(R.id.fl_cocos_view_container);
        container = $(R.id.container);
        fl_main = $(R.id.fl_main);

        mViewPager = $(R.id.main_vp_pager);
        main_rg_tab.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                tabH = main_rg_tab.getHeight() * 2;//mAppBarLayout 影响到
                if (mDiscoveryFragment != null && tabH > 0) {
                    mDiscoveryFragment.setTabH(tabH);
                    main_rg_tab.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        });

        $(R.id.main_rb_action).setOnClickListener(this);
        if (savedInstanceState != null) {
            mSelectTabId = savedInstanceState.getInt(BUNDLE_NAME_SELECT_TAB_ID);
        }
        initTabView();
        UserInfoModel userModel = UserInfoCache.getUserInfo();
        if (userModel != null) {
            if (userModel.getStat().getFollow() >= 20) {
                mSelectTabId = radiodynamics.getId();
            } else {
                mSelectTabId = radiodiscovery.getId();
            }
        }

        mViewPager.setOffscreenPageLimit(mTabButtonArray.size());
        initFragment();
        mDiscoveryFragment.setTabH(tabH);
        profileSysNoticeView = getProfileSysNoticeView();
        titleBar.getLeftView().addView(profileSysNoticeView);
        setTitleBarClickListener();
        loadSystemNoticeRed();
        loadSysParamGameShow();
        UnreadManager.getInstance().registerSocketListener(this);
        DynamicsNotifyManager.getInstance().registerDynamicNotifyListener(dynamicsFragmentHandler);

//        if (fl_cocos_view_container.getChildCount() == 0) {
//            IMayCocos.getInstance().removeCocosViewParent();
//            fl_cocos_view_container.addView(IMayCocos.getInstance().getCocosView());
//            IMayCocosNetManager.getInstance().setOnCocosShopListener(this);
//
//        }
        IMayCocosNetManager.getInstance().setOnCocosShopListener(this);
        addCocosView(fl_cocos_view_container);
        if (!hasout) {//互斥
            checkUpdateApp = new CheckUpdateApp();
            if (!checkUpdateApp.showDialog(MainActivity.this.getSupportFragmentManager())) {
                RoomLiveShortActivity.startActivity(MainActivity.this,true);
                registerSocketNotify();
            } else {
                willshow = false;
            }
        }
        mViewPager.post(new Runnable() {
            @Override
            public void run() {
                selectTab(mSelectTabId);
            }
        });

    }

    */
/**
     * 符合TAb 展示建楼卡
     *//*

    private void showRoomHouse() {
        if ((adsPersenter != null && adsPersenter.getAdsFragment() != null && adsPersenter.getAdsFragment().isVisible())) {
            return;
        }
        if (roomHouseHelper != null && ((radiodynamics.getId() == mSelectTabId || radiodiscovery.getId() == mSelectTabId) && !ispause && !cocosViewShowing)) {
            bringCocosViewToFront();
            roomHouseHelper.showHouseCard();
        }
    }

    //升级变化
    private void registerSocketNotify() {
        mSocketNotify = new IMYTBASObject(false);
        mSocketNotify.stringCommand = EventHelper.EVENT_APPUPDATE;
        mSocketNotify.setDataResultListener(new IMYTBASObject.OnDataResultListener() {
            @Override
            public void onCommandTaskSuccess(IMYTBASObject object) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (mSocketNotify != null) {
                            mSocketNotify.destroy();
                        }
                        if (ispause || checkUpdateApp == null) {
                            return;
                        }
                        checkUpdateApp.showDialog(MainActivity.this.getSupportFragmentManager());
                    }
                });
            }
        });
        mSocketNotify.addEventListenWithTBASObject();
    }

    */
/**
     * 初始化Permission
     *//*

    private void initPermission() {
        //检查定位权限
        mShowLocation = checkLocationPermission(true);
        setLocationStatus();

        mShowExternalStorage = checkExternalStoragePermission(true);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP && mLastVerticalOffset != 0) {
            mAppBarLayout.setExpanded(mExpanded);
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected boolean useDynamicTitleBar() {
        return false;
    }

    private void initFragment() {
        DynamicsFragment mDynamicsFragment = DynamicsFragment.newInstance();
        mDiscoveryFragment = DiscoveryFragment.newInstance();
        noticeFragment = NoticeFragment.newInstance();
        ProfileFragment four = ProfileFragment.newInstance(0);

        if (mViewPagerAdapter == null) {
            mViewPagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), mDynamicsFragment, mDiscoveryFragment, noticeFragment, four);
            mViewPager.setAdapter(mViewPagerAdapter);
        }
    }

    //初始化tab按钮
    private void initTabView() {
        //特殊处理点击事件
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectTab(v.getId());
                showSomeThing();
            }
        };
        //动态添加RadioButton到数组
//        for (int id : TAB_IDS) {
        radiodynamics = $(R.id.main_rb_dynamics);
        radiodynamics.setOnClickListener(listener);
        radiodynamics.setRadioButtonBG(R.mipmap.dongtaitubiao_2, R.mipmap.dongtaitubiao_1, getResources().getString(R.string.str_tab_dongtai));
        radiodynamics.setCheck(true);
        mTabButtonArray.append(radiodynamics.getId(), radiodynamics);

        radiodiscovery = $(R.id.main_rb_discovery);
        radiodiscovery.setOnClickListener(listener);
        radiodiscovery.setRadioButtonBG(R.mipmap.faxian_2, R.mipmap.faxian_1, getResources().getString(R.string.str_tab_faxian));
        mTabButtonArray.append(radiodiscovery.getId(), radiodiscovery);

        radionotice = $(R.id.main_rb_notice);
        radionotice.setOnClickListener(listener);
        radionotice.setRadioButtonBG(R.mipmap.tongzhi_2, R.mipmap.tongzhi_1, getResources().getString(R.string.str_tab_tongzhi));
        mTabButtonArray.append(radionotice.getId(), radionotice);

        radiomine = $(R.id.main_rb_mine);
        radiomine.setOnClickListener(listener);
        radiomine.setRadioButtonBG(R.mipmap.zhuye_2, R.mipmap.zhuye_1, getResources().getString(R.string.str_tab_me));
        mTabButtonArray.append(radiomine.getId(), radiomine);
    }

    //切换tab
    private void selectTab(final int id) {
        if (mTabButtonArray != null) {
            for (int i = 0; i < mTabButtonArray.size(); i++) {
                int key = mTabButtonArray.keyAt(i);
                NavigationTabView radioButton = mTabButtonArray.get(key);
                if (key == id) {
                    if (getTitleBar() != null) {
                        getTitleBar().setTitle(getString(TAB_TITLES[i]));
                    }
                    // 修改CoordinatorLayout布局的依赖文件
                    if (i == 0) {
                        if (dynamicsFragmentHandler != null) {
                            dynamicsFragmentHandler.obtainMessage(DynamicsFragment.ACTION_1).sendToTarget();
                        }
                        openCoordBehavior();
                    } else {
                        closeCoordBehavior();
                    }
                    mViewPager.setCurrentItem(i, false);
                    radioButton.setCheck(true);
                    startTabAnimtor(radioButton);
                } else {
                    radioButton.setCheck(false);
                }
            }
            setImageViewShowStatuByTabId(id);
        }
        if (radiodynamics.getId() == id) {
            MobclickAgent.onEvent(this, "dynamics_click");
            if (mSelectTabId == id) {
                if (dynamicsFragmentHandler != null) {
                    dynamicsFragmentHandler.obtainMessage(DynamicsFragment.ACTION_2).sendToTarget();
                }
            }
        } else if (radiodiscovery.getId() == id) {
            MobclickAgent.onEvent(this, "find_click");
            if (mSelectTabId == id) {
                mDiscoveryFragment.scrollTop();
            }
        } else if (radiomine.getId() == id) {
            MobclickAgent.onEvent(MainActivity.this, "personal_click");
        }
        mSelectTabId = id;
        if (mSelectTabId == radiodiscovery.getId()) {
            iv_bgwen.setVisibility(View.VISIBLE);
        } else {
            iv_bgwen.setVisibility(View.GONE);
        }
    }

    public void showSomeThing() {
        show = 0;
        if (radiodynamics.getId() == mSelectTabId) {
            show = 1;
        } else if (radiodiscovery.getId() == mSelectTabId) {
            show = 2;

        } else if (radiomine.getId() == mSelectTabId) {
            show = 3;
        }
        if (adsPersenter == null) {
            adsPersenter = new AdsPersenter(this);
        }
        adsPersenter.showads(show, this);
    }

    public int getShow() {
        return show;
    }

    */
/**
     * 开启依赖
     *//*

    public void openCoordBehavior() {
        if (main_rg_tab != null && mAppBarLayout != null) {
            AppBarLayout.Behavior behavior = new AppBarLayout.Behavior(this, null);
            CoordinatorLayout.LayoutParams p1 = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
            p1.setBehavior(behavior);
            ByeBurgerBehavior.from(main_rg_tab).setCanHide(true);
            ByeBurgerBehavior.from(main_rg_tab).setFirstY(main_rg_tab.getY());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (mViewPager != null) {
                    mViewPager.setNestedScrollingEnabled(true);
                }
            }
        }
    }

    */
/**
     * 关闭依赖
     *//*

    public void closeCoordBehavior() {
        if (main_rg_tab != null && mAppBarLayout != null) {
            ByeBurgerBehavior.from(main_rg_tab).setCanHide(false);
            CoordinatorLayout.LayoutParams p1 = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
            p1.setBehavior(null);
            mAppBarLayout.postDelayed(new Runnable() {
                @Override
                public void run() {
                    scaleTitleBar(0);
                }
            }, 100);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (mViewPager != null) {
                    mViewPager.setNestedScrollingEnabled(false);
                }
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        ispause = false;
////        if (IMayCocosNetManager.getInstance().getLauncherState() == 2) {
//            IMayCocos.getInstance().setOnCocosUpdateListener(new IMayCocos.OnCocosUpdateListener() {
//                @Override
//                public void onCocosAllowAction(int state) {
//                }
//            });
////            bringCocosViewToFront();
////        }
        mAppBarLayout.addOnOffsetChangedListener(this);

        //重新检查定位权限
        if (mWaitCheckLocalPermission) {
            mWaitCheckLocalPermission = false;
            mShowLocation = checkLocationPermission(false);
            setLocationStatus();
        }

        //重新SD权限
        if (mWaitCheckSDPermission) {
            mWaitCheckSDPermission = false;
            mShowLocation = checkLocationPermission(false);
        }
        if (checkUpdateApp != null) {
            checkUpdateApp.showDialog(MainActivity.this.getSupportFragmentManager());
            willshow = checkUpdateApp.getUpdateAppFragment() == null;
        }
        if (willshow) {
            showSomeThing();
        }
        willshow = true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        ispause = true;
        mAppBarLayout.removeOnOffsetChangedListener(this);
    }

    @Override
    public void onBackPressed() {
        if (IMayCocosNetManager.getInstance().getLauncherState() == 2) {
            return;
        }
        if (cocosViewShowing) {
            IMayCocos.closeMarketPannel();
            IMayCocos.closeRoomHouse();
            onCloseShopUI();
            return;
        }
        // 两秒内连按两次返回键退出程序
        long time = System.currentTimeMillis();
        if (time - mPressBackTime > 2000) {
            mPressBackTime = time;
        } else {
            IMApplication.getInstance().exit();
        }
    }


    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (verticalOffset > 0) {
            return;
        }
        boolean hide = verticalOffset < 0;
        if (hide != appLayoutHide) {
            appLayoutHide = hide;
            dynamicsFragmentHandler.obtainMessage(DynamicsFragment.ACTION_4, hide).sendToTarget();
        }

        mExpanded = mLastVerticalOffset < verticalOffset;
        mLastVerticalOffset = verticalOffset;
        scaleTitleBar(verticalOffset);

        int position = mViewPager.getCurrentItem();
        BaseFragment fragment = (BaseFragment) mViewPagerAdapter.getItem(position);
        fragment.setSpringViewEnable(verticalOffset == 0);
    }

    private void scaleTitleBar(int verticalOffset) {
        float offsetPercent = verticalOffset / mTitleBarHeight;
        float toScale = 1 + (offsetPercent * 3 / 7F);
        float toAlpha = 1 + (offsetPercent * 10 / 7F);
        ScaleAnimation leftScaleAnimation = null;
        ScaleAnimation rightScaleAnimation = null;
        ScaleAnimation scaleAnimation = null;
        AlphaAnimation alphaAnimation = null;
        if (mLastScale != toScale) {
            leftScaleAnimation = new ScaleAnimation(mLastScale, toScale, mLastScale, toScale, Animation.RELATIVE_TO_SELF, 1F, Animation.RELATIVE_TO_PARENT, 1F);
            rightScaleAnimation = new ScaleAnimation(mLastScale, toScale, mLastScale, toScale, Animation.RELATIVE_TO_SELF, 0F, Animation.RELATIVE_TO_PARENT, 1F);
            scaleAnimation = new ScaleAnimation(mLastScale, toScale, mLastScale, toScale, Animation.RELATIVE_TO_SELF, 0.5F, Animation.RELATIVE_TO_PARENT, 1F);
            mLastScale = toScale;
        }
        if (mLastAlpha != toAlpha && toAlpha <= 1) {
            alphaAnimation = new AlphaAnimation(mLastAlpha, toAlpha);
            mLastAlpha = toAlpha;
        }
        if (scaleAnimation != null || alphaAnimation != null) {
            AnimationUtil.startAnimation(getTitleBar().getLeftView(), leftScaleAnimation, alphaAnimation);
            AnimationUtil.startAnimation(getTitleBar().getMiddleView(), scaleAnimation, alphaAnimation);
            AnimationUtil.startAnimation(getTitleBar().getRightView(), rightScaleAnimation, alphaAnimation);
        }
        if (mTitleBarHeight + verticalOffset == 0) {    //完全移除屏幕
            if (mAppBarLayout.getAlpha() == 1) {
                mAppBarLayout.setAlpha(0.9F);
            }
        } else {
            if (mAppBarLayout.getAlpha() != 1) {
                mAppBarLayout.setAlpha(1F);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AccountManager.getInstance().clear();
        DynamicsNotifyManager.getInstance().unregisterDynamicNotifyListener();
        IMayCocosNetManager.getInstance().setOnCocosShopListener(null);
        if (mSocketNotify != null) {
            mSocketNotify.destroy();
        }
        if (dynamicsFragmentHandler != null) {
            dynamicsFragmentHandler.removeCallbacksAndMessages(null);
        }
    }

    @Override
    public void onClick(View v) {
        if (checkUpdateApp != null) {
            checkUpdateApp.onClick(v);
            checkUpdateApp = null;
        }
        switch (v.getId()) {
            case R.id.main_rb_action:
                showActionButton();
                break;
            case R.id.cl_profile_system_notice:
                SystemNoticeActivity.start(this);
                MobclickAgent.onEvent(MainActivity.this, "personal_click_notice");
                break;

        }
    }

    public void reloadData(boolean refresh) {
        if (mDiscoveryFragment != null)
            mDiscoveryFragment.reloadData(refresh);
    }

    private void showActionButton() {
        DialogFragmentHelper.showDialogFragment(getSupportFragmentManager(), MainActionButtonFragment.newInstance());
        MobclickAgent.onEvent(MainActivity.this, "action_click");
    }

    */
/**
     * 给tab添加点击动画
     *
     * @param view
     *//*

    private void startTabAnimtor(View view) {
        if (mTabAnimator == null) {
            mTabAnimator = AnimatorInflater.loadAnimator(this, R.animator.home_tab_anim);
        }
        mTabAnimator.setTarget(view);
        mTabAnimator.start();
    }

    private void setTitleBarClickListener() {
        getTitleBar().setLeftImageOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TitleBarClickHelper.leftTitleBarClick(mSelectTabId, R.id.main_rb_mine, MainActivity.this);
                TitleBarClickHelper.leftTitleBarClick(mSelectTabId, R.id.main_rb_discovery, MainActivity.this);
            }
        });
        getTitleBar().setRightImageOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (mSelectTabId) {
                    case R.id.main_rb_dynamics: //动态
                        if (dynamicsFragmentHandler != null) {
                            dynamicsFragmentHandler.obtainMessage(DynamicsFragment.ACTION_0).sendToTarget();
                        }
                        break;
                }
                TitleBarClickHelper.rightTitleBarClick(mSelectTabId, R.id.main_rb_mine, MainActivity.this);
                TitleBarClickHelper.rightTitleBarClick(mSelectTabId, R.id.main_rb_discovery, MainActivity.this);
            }
        });

    }

    public void changeRightIv(boolean isLinearFragmentStatus) {
        if (isLinearFragmentStatus) {
            getTitleBar().setRightImageResource(R.mipmap.btn_00label1);
        } else {
            getTitleBar().setRightImageResource(R.mipmap.btn_00label2);
        }
    }

    public void setDynamicsHandler(Handler handler) {
        this.dynamicsFragmentHandler = handler;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case Constants.REQUEST_PICK_IMAGE:
                if (resultCode == Activity.RESULT_OK) {
                    if (data == null) {
                        return;
                    }
                    Bundle b = data.getExtras();
                    String imagePath = b.getString("filePath");
                    ReleaseActivity.startActivity(this, imagePath, null, null, ReleaseActivity.IMAGE, Constants.DYNAMICSFEED_REQUEST_CODE);
                }
                break;
            case Constants.REQUEST_PICK_VIDEO:
                if (resultCode == Activity.RESULT_OK) {
                    if (data == null) {
                        return;
                    }
                    Bundle b = data.getExtras();
                    String movPath = b.getString("filePath");
                    String imgPath = b.getString("imagePath");
                    ReleaseActivity.startActivity(this, imgPath, movPath, null, ReleaseActivity.MOVIE, Constants.DYNAMICSFEED_REQUEST_CODE);
                }
                break;
            default:
                if (mSelectTabId == radiomine.getId()) {
                    FragmentManager fragmentManager = getSupportFragmentManager();
                    Fragment f = fragmentManager.getFragments().get(3);
                    f.onActivityResult(requestCode, resultCode, data);
                }
        }
    }

    */
/**
     * 设置titlebar 的左右控件的显示状态
     *
     * @param id
     *//*

    private void setImageViewShowStatuByTabId(int id) {
        switch (id) {
            case R.id.main_rb_dynamics:
                profileSysNoticeView.setVisibility(View.GONE);
                titleBar.setLeftViewVisibility(false);
                titleBar.setRightTextVisibility(false);
                dynamicsFragmentHandler.obtainMessage(DynamicsFragment.ACTION_5).sendToTarget();
                //titleBar.setRightImageResource(R.mipmap.btn_00label2);
                break;
            case R.id.main_rb_discovery:
                profileSysNoticeView.setVisibility(View.GONE);
                titleBar.setLeftImageResource(R.mipmap.btn_02sousuo);
                titleBar.setRightTextVisibility(false);
                titleBar.setRightImageResource(R.mipmap.btn_02paiming);
                break;
            case R.id.main_rb_notice:
                titleBar.setLeftViewVisibility(false);
                noticeFragment.showIgnoreUnreadBtn();
                titleBar.setRightImageResource(0);
                profileSysNoticeView.setVisibility(View.GONE);
                break;
            case R.id.main_rb_mine:
                profileSysNoticeView.setVisibility(View.VISIBLE);
                titleBar.setLeftViewVisibility(true);
                titleBar.setLeftImageVisibility(false);
                titleBar.setRightTextVisibility(false);
                titleBar.setRightImageResource(R.mipmap.btn_05t_shezhi);
                break;
        }

    }

    private View getProfileSysNoticeView() {
        profileSysNoticeView = LayoutInflater.from(this).inflate(R.layout.view_system_notice, null);
        iv_profile_system_notice_red = ViewUtil.findView(profileSysNoticeView, R.id.iv_profile_system_notice_red);
        profileSysNoticeView.setOnClickListener(this);
        profileSysNoticeView.setVisibility(View.GONE);
        return profileSysNoticeView;
    }

    */
/**
     * ==========权限=============
     *//*


    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[],
                                           int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_CODE_LOCATION:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // 用户允许，开启定位
                    mShowLocation = true;
                    setLocationStatus();
                }
                break;
            case PERMISSION_REQUEST_CODE_EXTERNAL_STORAGE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    mShowExternalStorage = true;
                }
                break;
        }
    }

    //检查定位权限，并获取定位
    private boolean checkLocationPermission(boolean showDialog) {
        try {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                if (showDialog) {
                    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)
                            || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)) {

                        showLocationPermissionDialog(getString(R.string.permission_location_title), getString(R.string.permission_location));
                    } else {
                        // 请求权限

                        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_CODE_LOCATION);
                    }
                }

                return false;
            } else {
                return true;
            }
        } catch (RuntimeException e) {
            Log.e("exception", "throw the runtimeException");
        }
        return false;
    }

    private boolean checkExternalStoragePermission(boolean showDialog) {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            if (showDialog) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
                    showSDPermissionDialog(getString(R.string.permission_sd_title), getString(R.string.permission_sd));
                } else {
                    // 请求权限
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE_EXTERNAL_STORAGE);
                }
            }
            return false;
        } else {
            return true;
        }
    }


    private void showLocationPermissionDialog(String title, String message) {
        DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), title, message,
                getString(R.string.permission_button_setting), null, false, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //activity恢复后是否再次检查权限
                        mWaitCheckLocalPermission = true;
                        AppUtil.startInstalledAppDetailsActivity(MainActivity.this);
                    }
                }, null);
    }

    private void showSDPermissionDialog(String title, String message) {
        DialogFragmentHelper.showConfirmDialog(getSupportFragmentManager(), title, message,
                getString(R.string.permission_button_setting), null, false, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //activity恢复后是否再次检查权限
                        mWaitCheckSDPermission = true;
                        AppUtil.startInstalledAppDetailsActivity(MainActivity.this);
                    }
                }, null);
    }

    //显示开启定位状态
    private void setLocationStatus() {
        //TODO 需要优化开启定位的流程
        if (mShowLocation) {
            getLocation();
        }
    }

    private void getLocation() {
        LocationHelper.getInstance().getLocation(this);
    }

    @Override
    public void onLocation(String city, double latitude, double longitude) {
        LocationHelper.getInstance().setCity(city);
        LocationHelper.getInstance().setLatitude(latitude);
        LocationHelper.getInstance().setLongitude(longitude);
    }

    */
/**
     * 加载系统消息红点
     *//*

    private void loadSystemNoticeRed() {
        loadSystemNoticeRedCommand = ProtoRequestHelper.task(ProtoHttpFactory.getSystemRedPoint()).setTag(this.hashCode()).request(this);
    }

    @Override
    public void onRequestSuccess(String command, String data) {
        if (command.equals(loadSystemNoticeRedCommand)) {
            Result<String> result = JSON.parseObject(data, new TypeReference<Result<String>>() {
            }.getType());
            if (result.result == CodeSuccess) {
                iv_profile_system_notice_red.setVisibility("T".equals(result.data) ? View.VISIBLE : View.GONE);
                radiomine.showRedPoint("T".equals(result.data));
            }
        } else if (command.equals(loadSysParamGameShowRequest)) {
            Result<SysConfigModel> result = JSON.parseObject(data, new TypeReference<Result<SysConfigModel>>() {
            }.getType());
            if (result.data != null && IMParams.CONFIGSWITCHGAMERANKMAIN.equals(result.data.getParamKey())) {
                if ("1".equals(result.data.getValue())) {
                    IMParams.isShowRankingGame = true;
                } else if ("0".equals(result.data.getValue())) {
                    IMParams.isShowRankingGame = false;
                }
            }
        }
    }

    @Override
    public void onRequestError(String command, int code, String message) {

    }


    //红点显示回调
    @Override
    public void onStatusChange(final UnreadModel unreadModel) {
        if (unreadModel == null) return;
        switch (unreadModel.getWarnType()) {
            case TYPE_UNREAD_SYSTEM_PROFILE:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        iv_profile_system_notice_red.setVisibility(unreadModel.haveUnread() ? View.VISIBLE : View.GONE);
                        radionotice.showRedPoint(unreadModel.haveUnread());
                    }
                });

                break;
            case MessageManager.NewWarnType.IMBubbleLiveType: // 直播间通知
                onLiveNotify(unreadModel.getValue());
                break;
            case IMBubbleCommentType:
            case IMBubbleMindType:
            case IMBubbleGiftType:
            case IMBubbleRePostType:
            case IMBubblePraiseType:
            case IMBubbleFollowType:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (unreadModel.haveUnread()) {
                            radionotice.showRedPoint(true);
                            if (hasLoadComplete) {
                                NoticeBubbleManager.getInstance().showBubbleDialog(MainActivity.this, unreadModel, radionotice);
                            }
                        } else {
                            NoticeBubbleManager.getInstance().clearMineNoticeUnreadData();
                            if (!hasUnreadMessage) {
                                radionotice.showRedPoint(false);
                            }
                        }
                        hasUnreadNotice = unreadModel.haveUnread();
                        if (noticeFragment != null) {
                            noticeFragment.refreshRedPoint(hasUnreadNotice, 0);
                        }

                    }
                });


                break;
            case TYPE_UNREAD_MESSAGE:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (unreadModel.haveUnread()) {
                            radionotice.showRedPoint(true);
                            unreadModel.setValue(noticeFragment.getRecentUnreadCount());
                            if (hasLoadComplete) {
                                NoticeBubbleManager.getInstance().showBubbleDialog(MainActivity.this, unreadModel, radionotice);
                            }
                        } else {
                            NoticeBubbleManager.getInstance().clearRecentMessageNoticeUnreadData();
                            if (!hasUnreadNotice) {
                                radionotice.showRedPoint(false);
                            }
                        }
                        hasUnreadMessage = unreadModel.haveUnread();
                        if (noticeFragment != null) {
                            noticeFragment.refreshRedPoint(hasUnreadMessage, 2);
                        }
                    }
                });
                break;
        }


    }

    @Override
    public void onLiveNotify(final int size) {
        ThreadManager.post(ThreadManager.THREAD_UI, new Runnable() {
            @Override
            public void run() {
                if (hasLoadComplete) {
                    radiodynamics.showRedPoint(true);
                    NoticeBubbleManager.getInstance().showLiveBubbleDialog(MainActivity.this, main_rg_tab, size);
                }
            }
        });
    }

    public void hideRedPoint() {
        radiodynamics.showRedPoint(false);
    }

    public void bringCocosViewToFront() {
        if (fl_cocos_view_container != null) {
            if (fl_cocos_view_container.getChildCount() == 0) {
                addCocosView(fl_cocos_view_container);
            }
            fl_main.bringChildToFront(fl_cocos_view_container);
            fl_main.updateViewLayout(fl_cocos_view_container, fl_cocos_view_container.getLayoutParams());
            cocosViewShowing = true;

        }
    }


    @Override
    public void onCloseShopUI() {
        revertCocosView();
    }

    private void revertCocosView() {
        fl_main.bringChildToFront(container);
        fl_main.updateViewLayout(container, container.getLayoutParams());
        cocosViewShowing = false;
        IMayCocos.getInstance().removeOnCocosUpdateListener(onCocosUpdateListener);
        onCocosUpdateListener = null;
    }

    IMayCocos.OnCocosUpdateListener onCocosUpdateListener;

    */
/**
     * 展示商城
     *//*

    public void showMarketPannel(final Integer mountId) {
        bringCocosViewToFront();
        if (onCocosUpdateListener != null) {//防止建楼卡
            IMayCocos.getInstance().removeOnCocosUpdateListener(onCocosUpdateListener);
        }
        onCocosUpdateListener = new IMayCocos.OnCocosUpdateListener() {
            @Override
            public void onCocosAllowAction(int state) {
                if (state == 3) {
                    IMayCocos.showMarketPanel(mountId);
                    MobclickAgent.onEvent(MainActivity.this, "mall_open");
                }
            }
        };
        IMayCocos.getInstance().addOnCocosUpdateListener(onCocosUpdateListener);
    }

    @Override
    public void onCocosRechargeClick() {
        RechargeActivity.start(this);
    }

    public void loadDiscoveryData(LoadFragment fragment, int refresh) {
        mDiscoveryFragment.reloadData(fragment, refresh);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        hasLoadComplete = hasFocus;
    }

    */
/**
     * 是否展示广告后的 建楼卡逻辑
     *//*

    @Override
    public void onShowAds(final AdsModel finalAdsItem) {
        if (IMayCocos.getInstance().getAppUpdateModel() != null || ispause || cocosViewShowing) {
            return;
        }
        if (finalAdsItem != null) {
            adsPersenter.saveAds(finalAdsItem);
            adsPersenter.showAdsView(getSupportFragmentManager(), finalAdsItem);
            return;
        }
        if ((radiodynamics.getId() == mSelectTabId || radiodiscovery.getId() == mSelectTabId)) {//不展示广告时候
            final boolean houseshow = AppUtil.showRoomHouseUi();
            if (!houseshow) {
                return;
            }
            if (roomHouseHelper == null) {
                roomHouseHelper = new RoomHouseHelper();
                roomHouseHelper.getHouseCard(new RoomHouseHelper.OnRoomHouseListener() {
                    @Override
                    public void onShowUI(final int rData, final int userLv) {
                        roomHouseHelper.setData(rData, userLv);
                        if (cocosViewShowing) {//预防商城打开
                            return;
                        }
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (onCocosUpdateListener == null) {
                                    onCocosUpdateListener = new IMayCocos.OnCocosUpdateListener() {
                                        @Override
                                        public void onCocosAllowAction(int state) {
                                            if (state == 3) {
                                                IMayCocos.getInstance().removeOnCocosUpdateListener(this);
                                                onCocosUpdateListener = null;

                                                if (roomHouseHelper.getrData() == 0) {
                                                    showRoomHouse();
                                                }
                                            }
                                        }
                                    };
                                    IMayCocos.getInstance().addOnCocosUpdateListener(onCocosUpdateListener);
                                }
                            }
                        });

                    }

                    @Override
                    public void onClose(final int receiveStatus) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (receiveStatus == 0) {
                                    IMayCocos.closeRoomHouse();
                                    onCloseShopUI();
                                }
                                roomHouseHelper = null;
                            }
                        });
                    }

                    @Override
                    public void onOpenH5(String url) {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append(url);
                        if (url.indexOf("?", 0) > -1) {
                            stringBuilder.append("&");
                        } else {
                            stringBuilder.append("?");
                        }
                        stringBuilder.append("uid=");
                        stringBuilder.append(AccountManager.getInstance().getUid());
                        if (AccountManager.getInstance().getToken() != null) {
                            stringBuilder.append("&accessToken=");
                            stringBuilder.append(AccountManager.getInstance().getToken().accessCode);
                        }
                        WebViewActivity.startActivity(MainActivity.this, url);
                        roomHouseHelper = null;
                    }
                });

            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (roomHouseHelper != null && roomHouseHelper.getrData() == 0 && onCocosUpdateListener == null && !cocosViewShowing) {
                            showRoomHouse();
                        }
                    }
                });
            }
        }
    }

    */
/**
     * 排行榜的
     *//*

    private void loadSysParamGameShow() {
        loadSysParamGameShowRequest = ProtoRequestHelper.task(ProtoHttpFactory.getRankingGameStatus()).setTag(this.hashCode()).request(this);
    }
}*/
